﻿using System;

#region MIT License text
/*
Copyright (c) 2009 Mark van Straten - Q42 B.V.

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
#endregion

namespace Q42.Wheels.Api.Nabaztag
{
    /// <summary>
    /// Control the LED's on the Nabaztag/tag
    /// </summary>
    public class LedChoreographyPart : ChoreographyPart
    {
        /// <summary>
        /// Location of the LED's when you look at your bunny
        /// </summary>
        public enum Leds { 
            /// <summary>
            /// Light on bottom side of nabaztag
            /// </summary>
            BottomLed = 0, 
            /// <summary>
            /// Middle line - Left led
            /// </summary>
            LeftLed = 3, 
            /// <summary>
            /// Middle line - Middle led
            /// </summary>
            MiddleLed = 2,
            /// <summary>
            /// Middle line - Right led
            /// </summary>
            RightLed = 1, 
            /// <summary>
            /// Led under the nose
            /// </summary>
            TopLed = 4
        }

        #region RGB attributes
        private Int16 red;
        /// <summary>
        /// Value of intensity for this LED (0 - 255)
        /// </summary>
        public Int16 Red
        {
            get { return red; }
            set
            {
                if (value < 0 || value > 255)
                    throw new ArgumentOutOfRangeException("RGB value can only be between 0 and 255");
                red = value;
            }
        }

        private Int16 blue;
        /// <summary>
        /// Value of intensity for this LED (0 - 255)
        /// </summary>
        public Int16 Blue
        {
            get { return blue; }
            set
            {
                if (value < 0 || value > 255)
                    throw new ArgumentOutOfRangeException("RGB value can only be between 0 and 255");
                blue = value;
            }
        }

        private Int16 green;
        /// <summary>
        /// Value of intensity for this LED (0 - 255)
        /// </summary>
        public Int16 Green
        {
            get { return green; }
            set
            {
                if (value < 0 || value > 255)
                    throw new ArgumentOutOfRangeException("RGB value can only be between 0 and 255");
                green = value;
            }
        }
        #endregion

        /// <summary>
        /// The LED controlled by this choreography
        /// </summary>
        private Leds led;
        /// <summary>
        /// The LED controlled by this choreography
        /// </summary>
        public Leds Led {
            get { return this.led; }
            private set { this.led = value; }
        }

        /// <summary>
        /// light up a LED on the bunny
        /// </summary>
        /// <param name="oActionTime"></param>
        /// <param name="oTheLed"></param>
        /// <param name="oRed">Light intensity in decimal from 0-255</param>
        /// <param name="oBlue">Light intensity in decimal from 0-255</param>
        /// <param name="oGreen">Light intensity in decimal from 0-255</param>
        public LedChoreographyPart(Int16 oActionTime, Leds oTheLed, Int16 oRed, Int16 oBlue, Int16 oGreen)
            : base(oActionTime)
        {
            Led = oTheLed;
            Red = oRed;
            Green = oGreen;
            Blue = oBlue;
        }

        /// <summary>
        /// Return the choreograpy for the Nabaztag/tag API in URL form
        /// </summary>
        /// <returns></returns>
        public override String GetChoreoGraphy()
        {
            return String.Format("{0},led,{1},{2},{3},{4}",ActionTime, (Int16) Led, Red, Green, Blue );
        }
    }
}
